The present invention is directed to an improved attribute analysis technique for use in compilers, and more particularly to a parser-based attribute analysis technique for use in compilers. The invention will be described in the context of PL/I programming, although it will be appreciated that this is by way of example only and that the invention is applicable to other programming languages as well.
When creating a program to run on a general purpose computer, the program is first written in source code, and the source code program is then passed through a compiler which converts the source code into object code, or machine language. There are several tasks performed by the compiler before finally generating an object code output, one of these tasks being performed by an "attribute processor" in the compiler front end. More particularly, when writing a PL/I source program, various "attributes" are assigned to data items used in the program, e.g., an item can be assigned the attribute of a variable or a constant, and a variable can be further assigned the attributes of PARAMETER, CONTROLLED, or STATIC. The most common way of assigning these attributes to data items is by way of a DECLARE statement, although attributes can also be assigned by a number of other techniques, e.g., a data description statement, a LIKE statement, or even inferentially by using a data item in a context which would require certain attributes. As generally shown in FIG. 1, the tasks performed by the attribute processor of a PL/I compiler during compilation of a PL/I source program include in a compilers apparatus: the checking of syntax correctness of attributes specified for each declared data item in the defining PL/I DECLARE statement, and representing this initial set of valid attributes in a concise internal notation; and completing the initial attribute set of each data item by providing the appropriate default values for any missing attributes, while checking the consistency and completeness of the final attribute set.
The attribute processor tasks must be performed in accordance with the syntax grammar defined in the American National Standard Institute (ANSI) PL/I standard, particularly chapter 4 thereof. The test for attribute consistency is set forth in .sctn.4.3.6.1 at pages 83-85. The purpose of the attribute consistency check is to ensure that no data item has been assigned inconsistent attributes, e.g., REAL and COMPLEX. The completion of the attribute set with default values is described in .sctn..sctn.4.3.6.3 through 4.3.6.5 at pages 86-88 of the ANSI PL/I standard. The checking to determine that the final attribute set is complete and consistent is described in .sctn.4.3.7.1 at page 93 of the ANSI PL/I standard. The tasks performed by the attribute processor of a PL/I compiler front end are not limited to only those steps set forth in the above-cited sections of the ANSI PL/I standard, but these sections exemplify the grammatical rules which must be followed in the attribute processor.
In conventional PL/I compilers, the attribute analysis is carried out by various ad hoc techniques, whereas default values are added, and completeness and consistency of the final attribute sets checked, by using specialized procedures, e.g., breaking the program down into small parts and sub-parts and then checking from inside to outside. This requires the writing of a great deal of code, typically generated manually by the programmer. This is not only time consuming and quite tedious, but the manual generation of the code is error-prone and substantial debugging of the compiler program is usually required. Investigating and correcting errors in a very long listing is a time consuming process.
Further, even after a working compiler is obtained, it is sometimes necessary to update the compiler to accommodate new or changed language features. As in the original generation of the compiler program, updating and debugging extensive object code listings implementing complex grammatical rules is a task which requires a substantial amount of programmer time.
For the above reasons, the generation of the attribute processor portion of the compiler program by conventional techniques is error prone, inefficient and difficult to adapt to new or changed language features, and it would be highly advantageous to provide a simplified and much faster technique for implementing the attribute processor portion of a compiler.